﻿using System;
using MbUnit.Framework;
using Quail;
using QuailTest.Pages;

namespace QuailTest
{
    [TestFixture]
    public class Demo6Test
    {
        private TestSession testsession;

        [SetUp]
        public void SetupTest()
        {
            testsession = new TestSession("Demo6Test");
            testsession.StartLogger(null);
            testsession.BrowserType = BrowserTypes.FireFox;
            testsession.StartBrowser("http://localhost/");
        }

        [TearDown]
        public void TeardownTest()
        {
            try
            {
                var ts = testsession;
                testsession = null;
                ts.Stop();
                ts.Dispose();
            }
            catch (Exception)
            {
                // Ignore errors if unable to close the browser
            }
        }

        [Test]
        public void TheQuailTestTestCase()
        {
            var page = new Demo6Page(testsession.Browser);
            page.NavigateToThisPage();

            var slv = page.Silverlight.Demo6Page;

            slv.Sync();

            slv.Eat.Click();
            slv.Doit.Click();
            slv.Sync();
            Assert.AreEqual("You ate a giant meatball", slv.Result.Value);

            slv.Sleep.Click();
            slv.Doit.Click();
            slv.Sync();
            Assert.AreEqual("You took a nap on the couch all day", slv.Result.Value);
        }
    }
}
